package utils

import (
	"fmt"
	"github.com/fatih/color"
	"github.com/gosuri/uitable"
	"music/api"
	"strconv"
)

func PrintMscTable(songs []api.Song) {

	table := uitable.New()
	table.MaxColWidth = 70
	table.AddRow(
		color.GreenString("序号"),
		color.GreenString("歌名"),
		color.GreenString("歌手"),
		color.GreenString("专辑"),
		color.GreenString("时长"),
	)
	for key, value := range songs {
		author := ""
		for _, val := range value.Artists {
			author += val.Name + " "
		}
		inx := strconv.Itoa(key + 1)

		min := value.Duration / 1000 / 60
		table.AddRow(
			color.YellowString(inx),
			value.Name,
			color.RedString(author),
			value.Album.Name,
			strconv.Itoa(min)+"分钟",
		)
	}
	fmt.Println(table)
}
